﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using BulldogCMS.Core;
using Newtonsoft.Json;

namespace BulldogCMS.Web
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        /*
         * Routing: local.sejcek.cz -> /Content/ComputerShop
         * local.sejcek.cz/products -> /Content/ComputerShop/Products
         * 
         */

        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new Core.MVC.RequestContextActionFilter());
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        }

        /*
         * Virtual Path Provider: http://stackoverflow.com/questions/7746253/using-custom-virtualpathprovider-to-load-embedded-resource-partial-views
         */

        protected void Application_Start()
        {
            RegisterRoutes(RouteTable.Routes);

            BulldogCMS.Core.Runtime.Runtime.LoadApplicationContext();
            BulldogCMS.Core.Runtime.Runtime.SetControllerFactory();
            BulldogCMS.Core.Runtime.Runtime.RegisterRoutes(RouteTable.Routes);
            BulldogCMS.Core.Runtime.Runtime.SetVirtualProvider();

            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(new RazorViewEngine());
            AreaRegistration.RegisterAllAreas();
            RegisterGlobalFilters(GlobalFilters.Filters);
        }
    }
}